<?php
$id = isset($_GET['id'])?$_GET['id']:'';
$id = (int)$id;


$html = g_url_contents('http://apikg.kktv1.com:8080/kkgame/entrance?callback=fonhen&parameter={%22FuncTag%22:60001002,%22roomId%22:%22'.$id.'%22,%22platform%22:1,%22a%22:2,%22c%22:100101}&_='.time());
	
$url = get_cutstr($html,'"liveStream":"','",');

if(!empty($url)){
	header("Location:".$url);
}

//直接跳转/下载
function show_down($data){
	if(isset($data[0]['url'])){
		header("Location:".$data[0]['url']);
	}
	exit;
}


function get_cutstr($str,$s1,$s2){
	$arr = explode($s1,$str);
	if(!empty($arr[1])){
		$arr = explode($s2,$arr[1]);
		return $arr[0];
	}else{
		return '';
	}
}


function g_url_contents($url,$reurl='',$ip=''){
		$user_agent = $_SERVER['HTTP_USER_AGENT'];
        $ch = curl_init();
        $timeout = 30;
        curl_setopt($ch,CURLOPT_URL,$url);
		if($ip){
			$header = array( 
				'CLIENT-IP:'.$ip, 
				'X-FORWARDED-FOR:'.$ip,
			);
			curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
		}
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
        curl_setopt($ch,CURLOPT_USERAGENT,$user_agent);
		curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
		
		if($reurl){
		     curl_setopt($ch,CURLOPT_REFERER,$reurl);
		}
        @ $c = curl_exec($ch);
        curl_close($ch);
        return $c;
}
?>